package concurrencyCookBook;

import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Four {

	public static void main(String[] args) {
		t2();
	}
	public static void t1(){
		Server server=new Server();
		server.server();
		server.shutDown();
	}
	
	public static void t2(){
		Task task=new Task("name");
		Thread t1=new Thread(task);
		Thread t2=new Thread(task);
		Thread t3=new Thread(task);
		t1.start();
		t2.start();
		t3.start();
		System.out.println(t1.getState());
	}

}
class Server{
	private ExecutorService executor;
	public Server(){
		//创建执行器
		this.executor=Executors.newCachedThreadPool();
	}
	public void server(){
		for (int i = 0; i < 10; i++) {
			Task task=new Task("taskName"+i);
			//执行任务
			executor.execute(task);
			
		}
	}
	public void shutDown(){
		executor.shutdown();
	}
}
class Task implements Runnable{
	private Date date;
	private String name;
	private int i=0;
	public Task(String name){
		this.name=name;
		this.date=new Date();
	}
	public Date getDate() {
		return date;
	}
	public void setDate(Date date) {
		this.date = date;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Override
	public void run() {

		for(int j=0;j<100;j++){
			try {
				Thread.sleep(10);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println(i++);
		}
		
		System.out.printf("Task:%s====name:%s===date:%s\n",Thread.currentThread().getName(),name,date);
	}
}
